
<?php
require('./Conn.php');
//
//CREATE OR REPLACE PROCEDURE SGA(C1 OUT SYS_REFCURSOR)  AS
//       
//BEGIN
//	OPEN C1 FOR select NAME, BYTES from v$sgainfo where NAME = 'Redo Buffers' or NAME = 'Buffer Cache Size' or NAME = 'Java Pool Size' or NAME = 'Shared Pool Size' or NAME= 'Streams Pool Size' or NAME = 'Large Pool Size';
//END SGA;
//
//show errors;

if (!isset($_POST['req'])) {
    die("No request provided.");
} else {
    if (filter_input(INPUT_POST, 'req') == "sga") {
        $json = array(
            'success' => false,
            'result' => array(),
            'rowCount' => 0
        );
        
        
         if (!$conn) {
            
            $m = oci_error();
            trigger_error(htmlentities($m['message']), E_USER_ERROR);
        }
        $curs = oci_new_cursor($conn);
        $stid = oci_parse($conn, "begin SGA(:cursbv); end;");
        oci_bind_by_name($stid, ":cursbv", $curs, -1, OCI_B_CURSOR);
        oci_execute($stid);

        oci_execute($curs);  // Execute the REF CURSOR like a normal statement id 
        
        $i =0;
        while ($row = oci_fetch_array($curs, OCI_ASSOC+OCI_RETURN_NULLS)) {
            array_push($json['result'], $row);
            $i++;
        }

        if ($i > 0) {
       
            $json['success'] = true;
            $json['rowCount'] =$i;
        }

        print( json_encode($json));
        
        }
        
        }
        

